package com.autonavi.yunda.yunji.controller.request;

import com.autonavi.yunda.yunji.common.exception.AmapPreconditions;
import com.autonavi.yunda.yunji.core.enums.FunctionStatus;
import com.autonavi.yunda.yunji.core.enums.FunctionType;
import com.autonavi.yunda.yunji.core.model.dto.FunctionConfigDTO;
import lombok.Data;

import java.util.List;

/**
 * @author sunzhenbang
 */
@Data
public class FunctionConfigRequest {
    private Long id;
    private String projectId;
    private String name;
    private String params;
    private String description;
    private FunctionType type;
    private String version;
    private String debugResult;
    private String functionScript;
    private List<String> projectIds;

    public FunctionConfigDTO toAddDTO(String employeeId) {
        return FunctionConfigDTO.builder()
                .name(name)
                .params(params)
                .description(description)
                .type(type)
                .status(FunctionStatus.INIT)
                .version(version)
                .debugResult(debugResult)
                .functionScript(functionScript)
                .createUser(employeeId)
                .updateUser(employeeId)
                .build();
    }

    public FunctionConfigDTO toUpdateDTO(String employeeId) {
        AmapPreconditions.checkNotNull(id, "id不能为空");
        return FunctionConfigDTO.builder()
                .id(id)
                .params(params)
                .description(description)
                .type(type)
                .debugResult(debugResult)
                .functionScript(functionScript)
                .updateUser(employeeId)
                .build();
    }
}
